package com.alipaydemo.pay.utils;

import lombok.Data;

@Data
public class Result<T> {
    private boolean result;
    private long current;
    private long size;

    private long total;
    private T data;
    private String msg;
    private Integer code;
//    public Result(){}
//
//
//    public Result(T data){
//        this.result=true;
//        this.msg=ResultEnum.SUCCESS.getMsg();
//        this.code=ResultEnum.SUCCESS.getCode();
//        this.data=data;
//    }
//
//    public Result(ResultEnum resultEnum){
//        this.msg=resultEnum.getMsg();
//        this.code=resultEnum.getCode();
//    }
    public Result(Integer code, String msg){
        this.code=code;
        this.msg=msg;
    }
//    public Result(){
//        this.result=true;
//        this.msg=ResultEnum.SUCCESS.getMsg();
//        this.code=ResultEnum.SUCCESS.getCode();
//    }
//    public Result(T data, Long total,BaseParam baseParam){
//        this.result=true;
//        this.msg=ResultEnum.SUCCESS.getMsg();
//        this.code=ResultEnum.SUCCESS.getCode();
//        this.data=data;
//        this.current=baseParam.getCurrent();
//        this.size=baseParam.getSize();
//        this.total=total;
//    }



    public static Builder builder(){
        return new Builder();
    }
    public static Builder builder(ResultEnum resultEnum){
        return new Builder(resultEnum);
    }
    public static Builder builder(Integer code,String msg){
        return new Builder(code, msg);
    }
    public static <R> Result<R> success() {
        Result<R> result = new Result(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg());
        return result;
    }
    public static  <R> Result<R> success(Object data) {
        Result<R> result = new Result(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg());
        result.setData((R) data);
        return result;
    }
    public  Result result(Boolean bool){
        this.result=bool;
        return this;
    }

    public  Result total(Long total){
        this.total=total;
        return this;
    }
    public  Result current(Long current){
        this.current=current;
        return this;
    }

    public  Result size(Long size){
        this.size=size;
        return this;
    }

   public static class Builder{
        private Integer code;
        private String msg;
        private Object data;

        public Builder(){
            this.code=ResultEnum.SUCCESS.getCode();
            this.msg=ResultEnum.SUCCESS.getMsg();
        }
       public Builder(ResultEnum resultEnum){
           this.code=resultEnum.getCode();
           this.msg=resultEnum.getMsg();
       }
       public Builder(Integer code,String msg){
           this.code=code;
           this.msg=msg;
       }
       public Builder data(Object data){
            this.data=data;
            return this;
       }


       public <R> Result<R> build() {
           Result<R> result = new Result(this.code, this.msg);
           result.setData((R) this.data);
           return result;
       }

   }

}
